using System;
using System.Reflection;
using TXLooker.Common;
using TXLooker.Common.FileFormatCoverters;

namespace TXLooker.WorkItemExtention.Core
{
    [Serializable]
    public class ContentPattern
    {
        public TextFormatType Format
        {
            get { return this.m_format; }
            set { this.m_format = value; }
        }
        private TextFormatType m_format = TextFormatType.Undefined;

        public string Pattern
        {
            get { return this.m_pattern; }
            set { this.m_pattern = value; }
        }
        private string m_pattern = null;

        public void SetDataFrom(object contentPattern)
        {
            try
            {
                Type type = contentPattern.GetType();

                object item = type.InvokeMember("Format", BindingFlags.GetProperty, null, contentPattern, null);
                string s = item.ToString();
                this.Format = (TextFormatType)Enum.Parse(typeof(TextFormatType), item.ToString());
                this.Pattern = (string)type.InvokeMember("Pattern", BindingFlags.GetProperty, null, contentPattern, null);
            }
            catch (Exception ex)
            {
                LogManager.WriteMessageToCustomLog("Error (SetDataFrom) ContentPattern " + ex.Message);
            }
        }
    }
}
